home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Java for 3D & VRML Worlds
/
Java for 3d and VRML Worlds.iso
/
vs
/
browser
/
cpb10ebx.exe
/
DATA.Z
/
cannon.java
< prev
next >
Wrap
Text File
|
1996-09-25
|
6KB
|
269 lines
/*
* File : cannon.java (Circus Park 2 for Community Place)
* Version : 2.0- 1996.09.10
* Auther : cori co.
*
* Copyright(C) 1996 Sony Corporation. All rights reserved.
*/
import vrml.*;
import vrml.field.*;
import vrml.node.*;
import java.util.*;
import vs.*;
public class cannon extends Script {
static int EVENT_VOID = 0;
static int EVENT_BOOL = 1;
static int EVENT_TIME = 2;
static int X = 0;
static int Y = 1;
static int Z = 2;
static int DEGREE = 3;
float Radian = 180.0f / (float)Math.PI;
/* Node */
SFNode CannonNode;
/* EventOut */
SFBool CannonSwitch;
SFVec3f RocketmanPosition;
SFRotation RocketmanRotation;
/* sound success */
SFTime CannonTrueSound_stop;
SFTime CannonTrueSound_start;
/* sound failure */
SFTime CannonFalseSound_stop;
SFTime CannonFalseSound_start;
/* sound bullet start */
SFTime CannonStartSound_stop;
SFTime CannonStartSound_start;
int CannonSwitchFlg = 0;
int CannonMoveCnt = -1;
float BulletAng;
float BulletOrgY = 0.0f;
float BulletOrgZ = -80.0f;
float BulletAccel;
float BulletY;
float BulletZ;
public void initialize() {
/* Node */
CannonNode = (SFNode) getField( "CannonNode" );
/* EventOut */
CannonSwitch = (SFBool) getEventOut( "CannonTimer_enabled" );
RocketmanPosition = (SFVec3f) getEventOut( "CannonRocketman_position" );
RocketmanRotation = (SFRotation) getEventOut( "CannonRocketman_rotation" );
/* sound success */
CannonTrueSound_stop = (SFTime) getEventOut( "CannonTrueSound_stop" );
CannonTrueSound_start = (SFTime) getEventOut( "CannonTrueSound_start" );
/* sound failure */
CannonFalseSound_stop = (SFTime) getEventOut( "CannonFalseSound_stop" );
CannonFalseSound_start = (SFTime) getEventOut( "CannonFalseSound_start" );
/* sound bullet start */
CannonStartSound_stop = (SFTime) getEventOut( "CannonStartSound_stop" );
CannonStartSound_start = (SFTime) getEventOut( "CannonStartSound_start" );
}
public void processEvent( Event e ) {
String name = e.getName();
double now = e.getTimeStamp();
if ( name.equals( "CannonSw1Click" )) {
CannonSw1Click( (ConstSFBool)e.getValue(), now );
} else if ( name.equals( "CannonSw2Click" )) {
CannonSw2Click( (ConstSFBool)e.getValue(), now );
} else if ( name.equals( "CannonSw3Click" )) {
CannonSw3Click( (ConstSFBool)e.getValue(), now );
} else if ( name.equals( "CannonMove" )) {
CannonMove( (ConstSFTime)e.getValue(), now );
} else if ( name.equals( "CannonStartShare" )) {
CannonStartShare( (ConstSFString)e.getValue(), now );
} else {
;
}
}
void cannon_init() {
float pos[] = new float[3];
pos[X] = 0.0f;
pos[Y] = BulletOrgY;
pos[Z] = BulletOrgZ;
RocketmanPosition.setValue( pos );
}
/*
* sound on/off
*/
public void soundSwitch( double now, boolean sw, boolean flg ) {
double time_st;
double time_ed;
time_st = now;
time_ed = time_st + 5;
if ( sw == true ) {
if ( flg == true ) {
CannonTrueSound_start.setValue( time_st );
CannonTrueSound_stop.setValue( time_ed );
} else {
CannonFalseSound_start.setValue( time_st );
CannonFalseSound_stop.setValue( time_ed );
}
} else {
if ( flg == true ) {
CannonTrueSound_stop.setValue(time_st);
} else {
CannonFalseSound_stop.setValue(time_st);
}
}
}
/*
* switch1 clicked
*/
public void CannonSw1Click ( ConstSFBool state, double now ) {
CannonSwitchChk ( state, now, 1 );
}
/*
* switch2 clicked
*/
public void CannonSw2Click ( ConstSFBool state, double now ) {
CannonSwitchChk ( state, now, 2 );
}
/*
* switch3 clicked
*/
public void CannonSw3Click ( ConstSFBool state, double now ) {
CannonSwitchChk ( state, now, 3 );
}
/*
* switch1-3 check
*/
public void CannonSwitchChk ( ConstSFBool state, double now, int sw_num ) {
int val;
String s;
if (state.getValue()) return; /* mouse down */
if ( CannonSwitchFlg >= 4 ) return; /* game over */
if ( sw_num == CannonSwitchFlg ) return; /* it is same button */
val = ( sw_num - CannonSwitchFlg );
if ( val == 1 ) { /* true sw */
CannonSwitchFlg++;
soundSwitch( now, true, true );
if ( CannonSwitchFlg == 3 ) {
CannonStart( now ); /* blast off the rocketman */
Vscp.sendApplSpecificMsgWithDist( CannonNode, "CannonStartShare", "dummy", Vscp.allClientsExceptMe );
}
} else { /* false sw */
CannonSwitchFlg = 0;
soundSwitch( now, true, false );
}
}
public void CannonStartShare ( ConstSFString shared_data, double now ) {
CannonStart( now );
}
/*
*
*/
public void CannonStart ( double now ) {
double time;
CannonSwitchFlg = 4;
time = now;
CannonStartSound_start.setValue(time);
time += 10;
CannonStartSound_stop.setValue(time);
CannonMoveCnt = 0;
BulletAng = 45.0f;
BulletY = BulletOrgY;
BulletZ = BulletOrgZ;
BulletAccel = 5.0f;
CannonSwitch.setValue( true );
}
/*
* timer event
*/
public void CannonMove ( ConstSFTime t, double now ) {
float pos[] = new float[3];
float rot[] = new float[4];
float angle_step, y_step, z_step;
String s;
angle_step = 3.0f;
z_step = 5.0f;
y_step = z_step / (float)(30 / 2);
if ( CannonMoveCnt < 0 ) { /* init only */
CannonSwitch.setValue( false );
cannon_init();
} else if ( CannonMoveCnt < 30 ) {
rot[X] = 1.0f; rot[Y] = 0.0f; rot[Z] = 0.0f;
rot[DEGREE] = BulletAng / Radian;
RocketmanRotation.setValue( rot );
BulletAng += angle_step;
pos[X] = 0.0f;
pos[Y] = BulletY;
pos[Z] = BulletZ + 10.0f;
RocketmanPosition.setValue( pos );
BulletZ += z_step;
BulletY += BulletAccel;
BulletAccel -= y_step;
} else if ( CannonMoveCnt == 30 ) {
rot[X] = 1.0f; rot[Y] = 1.0f; rot[Z] = 1.0f; rot[DEGREE] = 0.0f;
RocketmanRotation.setValue( rot );
BulletY = BulletOrgY;
} else if ( CannonMoveCnt < 60 ) {
pos[X] = 0.0f;
pos[Y] = BulletY;
pos[Z] = BulletZ;
RocketmanPosition.setValue( pos );
BulletZ -= z_step;
} else if ( CannonMoveCnt == 60 ) {
BulletZ = BulletOrgZ;
pos[X] = 0.0f;
pos[Y] = BulletY;
pos[Z] = BulletZ;
RocketmanPosition.setValue( pos );
CannonSwitchFlg = 0;
CannonSwitch.setValue( false );
}
CannonMoveCnt++;
}
}